package
{
	import SEApp.se_app;
	import SEApp.se_sapp;
	
	import UIFree.ObjectEvent;
	import UIFree.controls.FloatingArea.uiff_area;
	import UIFree.controls.FloatingArea.uiff_frame;
	import UIFree.controls.base.uif_source;
	import UIFree.uif_app;
	import UIFree.uif_ecomponent;
	import UIFree.uif_styles;
	
	import UIUtils.uif_cache;
	import UIUtils.uif_json;
	
	import classes.clt_styles;
	
	import components.google.clt_searchLayer;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	
	[SWF(width="760", height="900", backgroundColor="#FFFFFF")]
	public class google_search extends se_app {
		private var _frame: uiff_frame;
		private var _source: uif_source;
		public function google_search() {
			super(stage.stageWidth, stage.stageHeight);
			searchInit();
		}
		
		override protected function getStyles():uif_styles {
			return new clt_styles();
		}
		
		protected function searchInit(): void {
			var rect: Rectangle = getInner();
			var _layer: clt_searchLayer = new clt_searchLayer(layers[0], new uif_cache(), rect.x, rect.y, rect.width, 200, 'block');
			_layer.addEvent(Event.SELECT, doItemSelect);
			rect.top += _layer.height;
			_source = new uif_source(layers[0], rect.x, rect.y, rect.width, rect.height, 'block');

		} 
		
		private function doItemSelect(e: ObjectEvent): void {
			_source.loadSource('http://images.weserv.nl/?url=' + (e.object.link as String).substr(7));
/*			
			var loader: URLLoader = new URLLoader(new URLRequest(e.object.link));
			loader.dataFormat = URLLoaderDataFormat.TEXT;
			loader.addEventListener(Event.COMPLETE, doComplete);
			
			function doComplete(e: Event): void {
				//a_loader.loadBytes(e.target.data as ByteArray);
			}
*/			
		}
		
		private function doMouseClick(e: MouseEvent): void {
			var item: uif_ecomponent = new uif_ecomponent(_frame.area, 
				_frame.area.nextXPos, _frame.area.mouseY, 10 + Math.random() * 100, 10 + Math.random() * 100, 'vRect');
		}
	}
}